package com.cardone.platform.common.action;

import com.cardone.common.annotation.RunAction;
import com.cardone.common.annotation.support.BeforeRunActionSupport;
import com.cardone.context.ContextHolder;
import com.cardone.platform.common.dto.EntityLogDto;
import com.cardone.platform.common.service.EntityLogService;
import org.apache.commons.collections.MapUtils;

import java.util.Map;
import java.util.UUID;

/**
 * Created by c100000002 on 15-1-26.
 */
public class BeforeEntityLogAction extends BeforeRunActionSupport {
    @Override
    protected void run(RunAction runAction, Map<String, Object> parameterMap) {
        final EntityLogDto insertEntityLog = new EntityLogDto();

        insertEntityLog.setId(UUID.randomUUID().toString());
        insertEntityLog.setTypeTypeCode(runAction.beforeTypeCode());
        insertEntityLog.setTypeCode(runAction.beforeCode());
        insertEntityLog.setCode(runAction.beforeCode());
        insertEntityLog.setUserId(MapUtils.getString(parameterMap, "userId"));
        insertEntityLog.setEntityId(MapUtils.getString(parameterMap, "id"));
        insertEntityLog.setMessage(MapUtils.getString(parameterMap, "message"));

        ContextHolder.getBean(EntityLogService.class).insertByCode(insertEntityLog);
    }
}
